package com.bojiu.lawsearch.lawsearch.model;

import lombok.Data;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author: afdiao
 * @Date：2020/3/23 10:16
 * @Description:
 */
@Data
public class OrderMessage implements Delayed {

    /**
     * 问题id
     */
    private Integer questionId;

    /**
     * 回答问题的工程师id
     */
    private Integer engineerId;

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 随机值
     */
    private String UUID;

    /**
     * 类型：
     * publish   任务的发布，到期没有解决直接退款
     * handle    工程师回答任务，到期没有确认答案，金额直接打给工程师
     */
    private String type;

    private long startTime = System.currentTimeMillis();

    private long time;

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert((startTime + time) - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        OrderMessage orderMessage = (OrderMessage) o;
        return (int) (this.getDelay(TimeUnit.MILLISECONDS) - orderMessage.getDelay(TimeUnit.MILLISECONDS));
    }
}
